home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 2 / AACD 2.iso / AACD / Magazine / GraphicsCards / StormMesa / demos / winpos.c < prev   
Encoding:
C/C++ Source or Header  |  1998-12-15  |  2.3 KB  |  121 lines

  1. /* $Id: winpos.c,v 3.1 1998/02/22 16:36:10 brianp Exp $ */
  2.  
  3. /*
  4.  * Example of how to use the GL_MESA_window_pos extension.
  5.  * Brian Paul   This file is in the public domain.
  6.  */
  7.  
  8.  
  9. /*
  10.  * $Log: winpos.c,v $
  11.  * Revision 3.1  1998/02/22 16:36:10  brianp
  12.  * changed image file and set unpack alignment to 1
  13.  *
  14.  * Revision 3.0  1998/02/14 18:42:29  brianp
  15.  * initial rev
  16.  *
  17.  */
  18.  
  19.  
  20. #include <math.h>
  21. #include <string.h>
  22. #include <stdlib.h>
  23. #include <stdio.h>
  24. #include "GL/glut.h"
  25.  
  26. #ifndef AMIGA
  27. #include "../util/readtex.c"   /* I know, this is a hack. */
  28. #else
  29. GLubyte *LoadRGBImage( const char *, GLint *, GLint *, GLenum *);
  30. #endif
  31.  
  32.  
  33. #ifndef M_PI
  34. #  define M_PI 3.14159265
  35. #endif
  36.  
  37. #define IMAGE "girl.rgb"
  38.  
  39.  
  40. static GLubyte *Image;
  41. static int ImgWidth, ImgHeight;
  42. static GLenum ImgFormat;
  43.  
  44.  
  45.  
  46. static void draw( void )
  47. {
  48.    GLfloat angle;
  49.    char *extensions;
  50.  
  51.    extensions = (char *) glGetString( GL_EXTENSIONS );
  52.    if (strstr( extensions, "GL_MESA_window_pos")==NULL) {
  53.       printf("Sorry, GL_MESA_window_pos extension not available.\n");
  54.       return;
  55.    }
  56.  
  57.    glClear( GL_COLOR_BUFFER_BIT );
  58.  
  59.    for (angle = -45.0; angle <= 135.0; angle += 10.0) {
  60.       GLfloat x = 50.0 + 200.0 * cos( angle * M_PI / 180.0 );
  61.       GLfloat y = 50.0 + 200.0 * sin( angle * M_PI / 180.0 );
  62.  
  63.       /* Don't need to worry about the modelview or projection matrices!!! */
  64. #ifdef GL_MESA_window_pos
  65.       glWindowPos2fMESA( x, y );
  66. #endif
  67.       glDrawPixels( ImgWidth, ImgHeight, ImgFormat, GL_UNSIGNED_BYTE, Image );
  68.    }
  69. }
  70.  
  71.  
  72.  
  73.  
  74. static void key( unsigned char key, int x, int y )
  75. {
  76.    switch (key) {
  77.       case 27:
  78.          exit(0);
  79.    }
  80. }
  81.  
  82.  
  83.  
  84. /* new window size or exposure */
  85. static void reshape( int width, int height )
  86. {
  87.    glViewport(0, 0, (GLint)width, (GLint)height);
  88. }
  89.  
  90.  
  91. static void init( void )
  92. {
  93.    Image = LoadRGBImage( IMAGE, &ImgWidth, &ImgHeight, &ImgFormat );
  94.    if (!Image) {
  95.       printf("Couldn't read %s\n", IMAGE);
  96.       exit(0);
  97.    }
  98.    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  99. }
  100.  
  101.  
  102.  
  103. int main( int argc, char *argv[] )
  104. {
  105.    glutInitWindowPosition(0, 0);
  106.    glutInitWindowSize(500, 500);
  107.    glutInitDisplayMode( GLUT_RGB );
  108.  
  109.    if (glutCreateWindow("winpos") <= 0) {
  110.       exit(0);
  111.    }
  112.  
  113.    init();
  114.  
  115.    glutReshapeFunc( reshape );
  116.    glutKeyboardFunc( key );
  117.    glutDisplayFunc( draw );
  118.    glutMainLoop();
  119.    return 0;
  120. }
  121.